<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
    xmlns:s="http://www.w3.org/2003/05/soap-envelope"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:drive="http://schemas.microsoft.com/robotics/2006/05/drive.html"
    xmlns:motor="http://schemas.microsoft.com/robotics/2006/05/motor.html"
    xmlns:brick="http://www.promrds.com/contracts/2008/01/genericbrick.html">

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:call-template name="MasterPage">
      <xsl:with-param name="head">
        <script language="javascript" type="text/javascript">
          <xsl:comment>
            <![CDATA[
function OpenOrClose(targetID, imageID)
{
  var targetPanel = document.getElementById(targetID);
  var imageToSwap = document.getElementById(imageID);
  if(targetPanel.style.display == 'block')
  {
    targetPanel.style.display='none';
    imageToSwap.src ='/resources/dss/Microsoft.Dss.Runtime.Home.Images.OpenMenu.gif';
  }
  else
  {
    targetPanel.style.display='block';
    imageToSwap.src ='/resources/dss/Microsoft.Dss.Runtime.Home.Images.CloseMenu.gif';
  }
}

//        ]]>
          </xsl:comment>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="s:Header">
    
  </xsl:template>
  
  <xsl:template match="brick:GenericBrickState">
    <table width="100%" align="center">
      <tr>
        <th colspan="2">
          Robot Configuration
        </th>
      </tr>
      <tr>
        <th width="20%">
          Connected:
        </th>
        <td>
          <xsl:value-of select="brick:Connected"/>
        </td>
      </tr>
      <tr class="odd">
        <th>
          Capabilities:
        </th>
        <td>
          <xsl:value-of select="brick:Capabilities"/>
        </td>
      </tr>
      <tr>
        <th>
          Serial Port:
        </th>
        <td>
          COM<xsl:value-of select="brick:Configuration/brick:SerialPort"/>, 
          <xsl:value-of select="brick:Configuration/brick:BaudRate"/> baud
        </td>
      </tr>
      <tr class="odd">
        <th>
          Timing:
        </th>
        <td>
          Delay: <xsl:value-of select="brick:Configuration/brick:Delay"/>,
          Timeout: <xsl:value-of select="brick:Configuration/brick:Timeout"/>,
          Polling: <xsl:value-of select="brick:Configuration/brick:PollingInterval"/>
        </td>
      </tr>
      <tr>
        <th>
          Messages Stats:
        </th>
        <td>
          <xsl:value-of select="brick:CommsStats/brick:MessagesSent"/> sent,
          <xsl:value-of select="brick:CommsStats/brick:ErrorCount"/> errors
        </td>
      </tr>
      <tr class="odd">
        <th>
          LED States:
        </th>
        <td>
          <xsl:value-of select="brick:LEDs"/>
        </td>
      </tr>
      <tr>
        <th>
          Switch States:
        </th>
        <td>
          <xsl:value-of select="brick:Switches"/>
        </td>
      </tr>
    </table>

    <table width="100%" align="center">
      <tr>
        <xsl:attribute name="onclick">
          <xsl:text>OpenOrClose('PowerTable','PowerMenu'); return false;</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOver">
          <xsl:text>this.style.cursor = 'hand';</xsl:text>
          <xsl:text>this.style.cursor = 'pointer';</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOut">
          <xsl:text>this.style.cursor = '';</xsl:text>
        </xsl:attribute>
        <th valign="middle" align="center" width="20">
          <img src="/resources/dss/Microsoft.Dss.Runtime.Home.Images.CloseMenu.gif"
               id="PowerMenu" alt="Open or Close" title="Open or Close" border="0" />
        </th>
        <th width="*">
          Drive Power
        </th>
      </tr>
    </table>
    <table id="PowerTable" width="100%" align="center" style="display:block;">
      <tr>
        <th width="20%">
          Left Power:
        </th>
        <td>
          <xsl:value-of select="brick:DrivePower/brick:LeftPower"/>
        </td>
      </tr>
      <tr>
        <th>
          Right Power:
        </th>
        <td>
          <xsl:value-of select="brick:DrivePower/brick:RightPower"/>
        </td>
      </tr>
    </table>

    <table width="100%" align="center">
      <tr>
        <xsl:attribute name="onclick">
          <xsl:text>OpenOrClose('SensorsTable','SensorsMenu'); return false;</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOver">
          <xsl:text>this.style.cursor = 'hand';</xsl:text>
          <xsl:text>this.style.cursor = 'pointer';</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOut">
          <xsl:text>this.style.cursor = '';</xsl:text>
        </xsl:attribute>
        <th valign="middle" align="center" width="20">
          <img src="/resources/dss/Microsoft.Dss.Runtime.Home.Images.CloseMenu.gif"
               id="SensorsMenu" alt="Open or Close" title="Open or Close" border="0" />
        </th>
        <th width="*">
          Sensors
        </th>
      </tr>
    </table>
    <table id="SensorsTable" width="100%" align="center" style="display:block;">
      <tr>
        <th width="20%">
          Name
        </th>
        <th width="5%">
          ID
        </th>
        <th>
          Type
        </th>
        <th>
          Function
        </th>
        <th>
          Location
        </th>
        <th>
          Value
        </th>
      </tr>
      <xsl:for-each select="brick:Sensors/brick:Device" >
        <tr>
          <td width="20%">
            <xsl:value-of select="brick:Name"/>
          </td>
          <td width="5%">
            <xsl:value-of select="brick:HardwareIdentifer"/>
          </td>
          <td>
            <xsl:value-of select="brick:Type"/>
          </td>
          <td>
            <xsl:value-of select="brick:Function"/>
          </td>
          <td>
            <xsl:value-of select="brick:Location"/>
          </td>
          <td>
            <xsl:value-of select="brick:Value"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>

    <table width="100%" align="center">
      <tr>
        <xsl:attribute name="onclick">
          <xsl:text>OpenOrClose('ActuatorsTable','ActuatorsMenu'); return false;</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOver">
          <xsl:text>this.style.cursor = 'hand';</xsl:text>
          <xsl:text>this.style.cursor = 'pointer';</xsl:text>
        </xsl:attribute>
        <xsl:attribute name="onMouseOut">
          <xsl:text>this.style.cursor = '';</xsl:text>
        </xsl:attribute>
        <th valign="middle" align="center" width="20">
          <img src="/resources/dss/Microsoft.Dss.Runtime.Home.Images.CloseMenu.gif"
               id="ActuatorsMenu" alt="Open or Close" title="Open or Close" border="0" />
        </th>
        <th width="*">
          Actuators
        </th>
      </tr>
    </table>
    <table id="ActuatorsTable" width="100%" align="center" style="display:block;">
      <tr>
        <th width="20%">
          Name
        </th>
        <th width="5%">
          ID
        </th>
        <th>
          Type
        </th>
        <th>
          Function
        </th>
        <th>
          Location
        </th>
        <th>
          Value
        </th>
      </tr>
      <xsl:for-each select="brick:Actuators/brick:Device" >
        <tr>
          <td width="20%">
            <xsl:value-of select="brick:Name"/>
          </td>
          <td width="5%">
            <xsl:value-of select="brick:HardwareIdentifer"/>
          </td>
          <td>
            <xsl:value-of select="brick:Type"/>
          </td>
          <td>
            <xsl:value-of select="brick:Function"/>
          </td>
          <td>
            <xsl:value-of select="brick:Location"/>
          </td>
          <td>
            <xsl:value-of select="brick:Value"/>
          </td>
        </tr>
      </xsl:for-each>
    </table>
  </xsl:template>

</xsl:stylesheet>
